package com.sc.nft.admin.request;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.sc.nft.entity.req.EcologyCastGasRequest;
import com.sc.nft.enums.ClassifyType;
import com.sc.nft.enums.CollectionLevel;
import com.sc.nft.enums.CommodityType;
import com.sc.nft.enums.NFTProductShowSalvagePrefectureEnum;
import com.sc.nft.exception.GlobalRunTimeException;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.Range;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.Date;
import java.util.Objects;

@Data
public class AddProductRequest {

    @ApiModelProperty("一级标题")
    @NotBlank(message = "一级标题不能为空")
    private String firstTitle;

    @ApiModelProperty("二级标题")
    private String secondTitle;

    @ApiModelProperty("缩略图")
    @NotBlank(message = "缩略图不能为空")
    private String creationContent;

    @ApiModelProperty("售卖价格")
    private BigDecimal productNum;

    @ApiModelProperty("稀有程度")
    private CollectionLevel level;

    @ApiModelProperty("等级")
    private Integer showLevel;

    @ApiModelProperty("积分价格")
    private BigDecimal integralNum;

    @ApiModelProperty("藏品/盲盒Id")
    private Long relationId;

    @ApiModelProperty("藏品数量（盲盒不需要）")
    private Integer productCount;

    @ApiModelProperty("作品故事")
    private String productPresentation;

    @ApiModelProperty("权益介绍")
    private String privilegePresentation;

    @ApiModelProperty("开始时间")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @NotNull(message = "开始时间不能为空")
    private Date beginTime;

    @ApiModelProperty("结束时间")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @NotNull(message = "结束时间不能为空")
    private Date endTime;

    @ApiModelProperty("系列id")
    private Long catenaId;

    @ApiModelProperty("系列名称")
    private String catenaName;

    @ApiModelProperty("详情页图类型 1 图片 2:动图 3:3d模型")
    @NotNull(message = "详情页图类型不能为空")
    private Integer productDetailPictureType;

    @ApiModelProperty("详情页图")
    @NotNull(message = "详情页图不能为空")
    private String productDetailPicture;

    @ApiModelProperty("商品类型 ")
    private CommodityType commodityType;

    @ApiModelProperty("分类")
    private ClassifyType typeClassify;

    @ApiModelProperty("购买上限")
    @Range(min = 1)
    private Integer upperLimit;

    @ApiModelProperty("是否是优先购商品")
    @NotNull(message = "请设置是否是优先购商品")
    private Boolean isPriorityPurchase;

    @ApiModelProperty("优先购上限")
    private Integer priorityPurchaseLimit;

    @ApiModelProperty("优先购上限(总量)")
    private Integer priorityPurchaseAllLimit;

    @ApiModelProperty("优先购开始时间")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date priorityPurchaseBeginTime;

    @ApiModelProperty("优先购结束时间")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date priorityPurchaseEndTime;

    @ApiModelProperty("是否是优先抢商品")
    @NotNull(message = "请设置是否是优先抢商品")
    private Boolean isRushBuy;

    @ApiModelProperty("优先抢数量")
    private Integer rushBuyLimit;

    @ApiModelProperty("优先抢开始时间")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date rushBuyBeginTime;

    @ApiModelProperty("优先抢结束时间")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date rushBuyEndTime;

    @ApiModelProperty("合成数量")
    private Integer synthesisCount;

    @ApiModelProperty("权益道具id")
    private Long equityPropsId;

    @ApiModelProperty("权益道具数量")
    private Integer equityPropsNum;

    @ApiModelProperty("铸造须知")
    private String ecologyCastPresentation;


    @ApiModelProperty("是否为仅熔炼")
    private Boolean isSmeltingOnly = Boolean.FALSE;


    @ApiModelProperty("分润模板Id")
    private Long shareProfitPanelId;

    @ApiModelProperty("是否锁仓")
    @NotNull(message = "请设置是否锁仓")
    private Boolean isLockedPosition;

    @ApiModelProperty("锁仓类型 0:省缺 1:时间模式 2:日期形式 时间模式是获取藏品后延后多久,日期形式是统一锁到对应的时间")
    private Integer lockedPositionType;

    @ApiModelProperty("锁仓市场小时")
    private Integer lockedPositionHour;

    @ApiModelProperty("锁仓到期日期")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date lockedPositionTime;

    @ApiModelProperty("是否为平台展示")
    private Boolean platformShow = true;

    @ApiModelProperty("是否为品牌岛展示")
    private Boolean brandShow = false;

    @ApiModelProperty("是否为企业展示")
    private Boolean firmShow = false;
    
    @ApiModelProperty("上链费配置")
    private EcologyCastGasRequest ecologyCastGas;


    @ApiModelProperty("展示专区")
    private NFTProductShowSalvagePrefectureEnum showSalvagePrefecture;

    @ApiModelProperty("是否开启注册时间限制")
    //    @NotNull(message = "是否开启注册时间限制不能为空")
    private Boolean isRegisterTime = Boolean.FALSE;

    @ApiModelProperty("注册开始时间")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date registerBeginTime;

    @ApiModelProperty("注册结束时间")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date registerEndTime;

    public void checkProductType(){
        if (CommodityType.ECOLOGY_COMMODITY == commodityType || CommodityType.ECOLOGY_REFORGE == commodityType){
            ecologyCastGas.checkEcologyCastGas();
        }
    }

    public Boolean lockedPositionDecide() {
        // 是否为锁仓
        if (!this.isLockedPosition) {
            return true;
        }
        // 是否为锁仓
        if (this.isLockedPosition) {
            // 是锁仓但是是省缺不允许
            if (this.lockedPositionType.equals(0)) {
                throw new GlobalRunTimeException("请设置锁仓类型");
            }
            // 锁时长模式
            if (this.lockedPositionType.equals(1)) {
                // 锁仓市场大小
                if (this.lockedPositionHour > 0 && this.lockedPositionHour <= 99999) {
                    return true;
                }
            }
            // 锁日期模式
            if (this.lockedPositionType.equals(2)) {
                // 锁仓到期日期必须大于当前时间
                if (this.lockedPositionTime.getTime() > System.currentTimeMillis()) {
                    return true;
                }
            }
        }
        return false;
    }
}
